import {  defineStore } from "pinia";
import { gameLogin } from "@/api/casion";
import { useRouter } from "vue-router";
import { mainAct } from "./activeda";
import { eventBus } from "@/utils/eventBus";
import { isMobile } from "@/utils/isMobile";
import i18n from "@/lang";

const store = mainAct();
export const gameDetail = defineStore("gameDetail", {
  state: () => {
    return {
      gameNav: null, //左侧导航游戏
    };
  },
  getters: {},

  actions: {
    gameLogin(gameCode, router) {
      store.isLoading = true;
      gameLogin({
        game_code: gameCode,
      }).then(res => {
        store.isLoading = false;
        eventBus.emit("closrIsLoading", false);

        console.log(' isMobile()', isMobile());
        let path = ''
        if (isMobile()) {
          path = '/phoneIframe'
        } else {
          path = 'iframe'
        }

        if (res.errno == 0) {

          eventBus.emit("game_enter", gameCode);
          router.push({
            path: path,
            query: {
              game_url: res.data.path,
              userToken: store.token
            }
          });


          // coupon_disable == 1 显示
          // 活动获取的金额不能在体育下注，体育游戏余额将会扣除活动金额。

          // wallet_rate = 1 显示
          // 投注NGN游戏将会为您的余额价值提升100倍，您可能会在游戏中看到您的余额缩小
          if (res.data.coupon_disable) {
            ElNotification({
              position: "top-left",
              zIndex: 1004,
              title: "",
              message: i18n.global.t("page.casino.sportsTip"),
              type: "success"
            });
          }

          if (res.data.wallet_rate != 1) {
            ElNotification({
              position: "top-left",
              zIndex: 1004,
              title: "",
              message: i18n.global.t("page.casino.wallet_rate"),
              type: "success"
            });
          }
          // window.open(res.data.path, "_blank");
        }  
      });
    }
  },

  persist: {
    enabled: true,
    detached: true,
    strategies: [
      // {
      //   key: "gameNav",
      //   storage: sessionStorage,
      //   paths: ["gameNav"]
      // },
    ]
  }
});